package com.xcx.robot.mirai.util;

import com.xcx.robot.annotation.ExceptionCatch;
import com.xcx.robot.mirai.QuickStart;
import com.xcx.robot.util.ImageUtils;
import net.mamoe.mirai.Mirai;
import net.mamoe.mirai.event.events.GroupMessageEvent;
import net.mamoe.mirai.message.data.FlashImage;
import net.mamoe.mirai.message.data.Image;
import org.springframework.stereotype.Component;

/**
 * @Author: 邢晨旭
 * @Date: 2021/7/1 09:31
 * @Description:
 */
@Component
public class ImageForRobot {

    @ExceptionCatch
    public void save(GroupMessageEvent event) {
        Image image = event.getMessage().get(Image.Key);
        FlashImage flashImage = event.getMessage().get(FlashImage.Key);
        if (image != null || flashImage != null) {
            //图片下载
            String downloadUrl = Mirai.getInstance().queryImageUrl(QuickStart.bot, image != null ? image : flashImage.getImage());
            ImageUtils.downloadPicture(downloadUrl, event.getGroup().getId(), event.getSender().getId(), event.getTime() + (flashImage != null ? "闪照" : ""));
        }
    }

}
